const Service = require("egg").Service;

class AccountService extends Service {

  async saveAccount ({ accountNumber, passWord }) {
    const { app } = this;
    try {
        return await app.model.Account.create({
          accountNumber,
          passWord
        });
    } catch (err) {
      console.log(err);
      throw new Error(err)
    }
  }

  async findAccountById (id) {
    const { app } = this;
    try {
      return await app.model.Account.findOne({
        where: { id },
      });
    } catch (err) {
      console.log(err);
      throw new Error(err)
    }
  }

  async findAccount (accountNumber) {
    const { app } = this;
    try {
      return await app.model.Account.findOne({
        where: { accountNumber },
      });
    } catch (err) {
      console.log(err);
      throw new Error(err)
    }
  }

}

module.exports =AccountService;
